--
-- PostgreSQL database dump
--

-- Started on 2012-12-07 00:45:18

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 504 (class 2612 OID 16386)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--

CREATE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 157 (class 1259 OID 16684)
-- Dependencies: 6
-- Name: acesso; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE acesso (
    data date
);


ALTER TABLE public.acesso OWNER TO postgres;

--
-- TOC entry 158 (class 1259 OID 24876)
-- Dependencies: 6
-- Name: chave; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE chave (
    chave character varying(12),
    status character varying(10),
    id integer NOT NULL
);


ALTER TABLE public.chave OWNER TO postgres;

--
-- TOC entry 159 (class 1259 OID 24879)
-- Dependencies: 158 6
-- Name: chave_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE chave_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.chave_id_seq OWNER TO postgres;

--
-- TOC entry 1889 (class 0 OID 0)
-- Dependencies: 159
-- Name: chave_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE chave_id_seq OWNED BY chave.id;


--
-- TOC entry 140 (class 1259 OID 16396)
-- Dependencies: 6
-- Name: consulta; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE consulta (
    id integer NOT NULL,
    data date NOT NULL,
    hora time without time zone NOT NULL,
    tipo character varying(20),
    status character varying(20),
    obs character varying(500),
    pagamento double precision,
    profissional character varying(30) NOT NULL,
    paciente integer NOT NULL,
    convenio character varying(30),
    texto character varying(5000),
    anamnese character varying(5000)
);


ALTER TABLE public.consulta OWNER TO postgres;

--
-- TOC entry 141 (class 1259 OID 16402)
-- Dependencies: 6 140
-- Name: consulta_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE consulta_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.consulta_id_seq OWNER TO postgres;

--
-- TOC entry 1890 (class 0 OID 0)
-- Dependencies: 141
-- Name: consulta_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE consulta_id_seq OWNED BY consulta.id;


--
-- TOC entry 142 (class 1259 OID 16404)
-- Dependencies: 6
-- Name: convenio; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE convenio (
    nome character varying(50) NOT NULL,
    telefone1 character varying(30),
    telefone2 character varying(30),
    valor_cobrado double precision,
    email character varying(50),
    cnpj character varying(30)
);


ALTER TABLE public.convenio OWNER TO postgres;

--
-- TOC entry 143 (class 1259 OID 16407)
-- Dependencies: 6
-- Name: funcionalidade; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE funcionalidade (
    id integer NOT NULL,
    nome character varying(100) NOT NULL
);


ALTER TABLE public.funcionalidade OWNER TO postgres;

--
-- TOC entry 144 (class 1259 OID 16410)
-- Dependencies: 6
-- Name: paciente; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE paciente (
    id integer NOT NULL,
    nome character varying(100) NOT NULL,
    cpf character varying(20),
    rg character varying(20),
    cartao_sus character varying(20),
    prontuario character varying(20),
    nascimento date NOT NULL,
    status character varying(20) NOT NULL,
    sexo character varying(20) NOT NULL,
    mae character varying(50),
    pai character varying(50),
    estado_civil character varying(20) NOT NULL,
    cor character varying(30),
    email character varying(50),
    telefone1 character varying(30),
    telefone2 character varying(30),
    escolaridade character varying(50),
    logradouro character varying(50) NOT NULL,
    numero character varying(10) NOT NULL,
    bairro character varying(50),
    cep character varying(20),
    complemento character varying(50),
    cidade character varying(50) NOT NULL,
    estado character varying(50) NOT NULL
);


ALTER TABLE public.paciente OWNER TO postgres;

--
-- TOC entry 145 (class 1259 OID 16416)
-- Dependencies: 6 144
-- Name: paciente_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE paciente_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.paciente_id_seq OWNER TO postgres;

--
-- TOC entry 1891 (class 0 OID 0)
-- Dependencies: 145
-- Name: paciente_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE paciente_id_seq OWNED BY paciente.id;


--
-- TOC entry 146 (class 1259 OID 16418)
-- Dependencies: 6
-- Name: perfil; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE perfil (
    nome character varying(20) NOT NULL
);


ALTER TABLE public.perfil OWNER TO postgres;

--
-- TOC entry 147 (class 1259 OID 16421)
-- Dependencies: 6
-- Name: perfil_funcionalidade; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE perfil_funcionalidade (
    perfil character varying(20) NOT NULL,
    funcionalidade integer NOT NULL,
    id integer NOT NULL
);


ALTER TABLE public.perfil_funcionalidade OWNER TO postgres;

--
-- TOC entry 148 (class 1259 OID 16424)
-- Dependencies: 147 6
-- Name: perfil_funcionalidade_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE perfil_funcionalidade_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.perfil_funcionalidade_id_seq OWNER TO postgres;

--
-- TOC entry 1892 (class 0 OID 0)
-- Dependencies: 148
-- Name: perfil_funcionalidade_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE perfil_funcionalidade_id_seq OWNED BY perfil_funcionalidade.id;


--
-- TOC entry 149 (class 1259 OID 16426)
-- Dependencies: 6
-- Name: profissional; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE profissional (
    cpf character varying(20) NOT NULL,
    registro character varying(30) NOT NULL,
    orgao_expedidor character varying(20),
    estado_expedidor character varying(20),
    rg character varying(30),
    categoria character varying(40) NOT NULL,
    especialidade character varying(30),
    nascimento date,
    telefone1 character varying(30),
    telefone2 character varying(30),
    email character varying(50),
    login character varying(20),
    sexo character varying(20),
    horario_trabalho character varying(50),
    valor_consulta money
);


ALTER TABLE public.profissional OWNER TO postgres;

--
-- TOC entry 150 (class 1259 OID 16429)
-- Dependencies: 6
-- Name: profissional_convenio; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE profissional_convenio (
    id integer NOT NULL,
    profissional character varying(20),
    convenio character varying(50)
);


ALTER TABLE public.profissional_convenio OWNER TO postgres;

--
-- TOC entry 151 (class 1259 OID 16432)
-- Dependencies: 150 6
-- Name: profissional_convenio_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE profissional_convenio_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.profissional_convenio_id_seq OWNER TO postgres;

--
-- TOC entry 1893 (class 0 OID 0)
-- Dependencies: 151
-- Name: profissional_convenio_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE profissional_convenio_id_seq OWNED BY profissional_convenio.id;


--
-- TOC entry 152 (class 1259 OID 16434)
-- Dependencies: 6
-- Name: receita; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE receita (
    id integer NOT NULL,
    texto character varying(500) NOT NULL,
    registro character varying(20) NOT NULL,
    consulta integer NOT NULL
);


ALTER TABLE public.receita OWNER TO postgres;

--
-- TOC entry 153 (class 1259 OID 16440)
-- Dependencies: 152 6
-- Name: receita_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE receita_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.receita_id_seq OWNER TO postgres;

--
-- TOC entry 1894 (class 0 OID 0)
-- Dependencies: 153
-- Name: receita_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE receita_id_seq OWNED BY receita.id;


--
-- TOC entry 154 (class 1259 OID 16442)
-- Dependencies: 6
-- Name: usuario; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE usuario (
    login character varying(20) NOT NULL,
    senha character varying(20) NOT NULL,
    status character varying(20) NOT NULL,
    nome character varying(100)
);


ALTER TABLE public.usuario OWNER TO postgres;

--
-- TOC entry 155 (class 1259 OID 16445)
-- Dependencies: 6
-- Name: usuario_perfil; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE usuario_perfil (
    usuario character varying(20) NOT NULL,
    perfil character varying(20) NOT NULL,
    id integer NOT NULL
);


ALTER TABLE public.usuario_perfil OWNER TO postgres;

--
-- TOC entry 156 (class 1259 OID 16448)
-- Dependencies: 6 155
-- Name: usuario_perfil_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE usuario_perfil_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.usuario_perfil_id_seq OWNER TO postgres;

--
-- TOC entry 1895 (class 0 OID 0)
-- Dependencies: 156
-- Name: usuario_perfil_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE usuario_perfil_id_seq OWNED BY usuario_perfil.id;


--
-- TOC entry 1841 (class 2604 OID 24881)
-- Dependencies: 159 158
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY chave ALTER COLUMN id SET DEFAULT nextval('chave_id_seq'::regclass);


--
-- TOC entry 1835 (class 2604 OID 16450)
-- Dependencies: 141 140
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY consulta ALTER COLUMN id SET DEFAULT nextval('consulta_id_seq'::regclass);


--
-- TOC entry 1836 (class 2604 OID 16451)
-- Dependencies: 145 144
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY paciente ALTER COLUMN id SET DEFAULT nextval('paciente_id_seq'::regclass);


--
-- TOC entry 1837 (class 2604 OID 16452)
-- Dependencies: 148 147
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY perfil_funcionalidade ALTER COLUMN id SET DEFAULT nextval('perfil_funcionalidade_id_seq'::regclass);


--
-- TOC entry 1838 (class 2604 OID 16453)
-- Dependencies: 151 150
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY profissional_convenio ALTER COLUMN id SET DEFAULT nextval('profissional_convenio_id_seq'::regclass);


--
-- TOC entry 1839 (class 2604 OID 16454)
-- Dependencies: 153 152
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY receita ALTER COLUMN id SET DEFAULT nextval('receita_id_seq'::regclass);


--
-- TOC entry 1840 (class 2604 OID 16455)
-- Dependencies: 156 155
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY usuario_perfil ALTER COLUMN id SET DEFAULT nextval('usuario_perfil_id_seq'::regclass);


--
-- TOC entry 1843 (class 2606 OID 16457)
-- Dependencies: 140 140
-- Name: consulta_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_id_key UNIQUE (id);


--
-- TOC entry 1845 (class 2606 OID 16459)
-- Dependencies: 140 140 140 140 140 140
-- Name: consulta_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_pkey PRIMARY KEY (id, data, hora, paciente, profissional);


--
-- TOC entry 1847 (class 2606 OID 16461)
-- Dependencies: 142 142
-- Name: convenio_cnpj_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY convenio
    ADD CONSTRAINT convenio_cnpj_key UNIQUE (cnpj);


--
-- TOC entry 1849 (class 2606 OID 16463)
-- Dependencies: 142 142
-- Name: convenio_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY convenio
    ADD CONSTRAINT convenio_pkey PRIMARY KEY (nome);


--
-- TOC entry 1851 (class 2606 OID 16465)
-- Dependencies: 143 143
-- Name: funcionalidade_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY funcionalidade
    ADD CONSTRAINT funcionalidade_pkey PRIMARY KEY (id);


--
-- TOC entry 1853 (class 2606 OID 16467)
-- Dependencies: 144 144
-- Name: paciente_cpf_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY paciente
    ADD CONSTRAINT paciente_cpf_key UNIQUE (cpf);


--
-- TOC entry 1855 (class 2606 OID 16469)
-- Dependencies: 144 144
-- Name: paciente_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY paciente
    ADD CONSTRAINT paciente_pkey PRIMARY KEY (id);


--
-- TOC entry 1857 (class 2606 OID 16471)
-- Dependencies: 144 144
-- Name: paciente_rg_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY paciente
    ADD CONSTRAINT paciente_rg_key UNIQUE (rg);


--
-- TOC entry 1861 (class 2606 OID 16473)
-- Dependencies: 147 147 147
-- Name: perfil_funcionalidade_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY perfil_funcionalidade
    ADD CONSTRAINT perfil_funcionalidade_pkey PRIMARY KEY (perfil, funcionalidade);


--
-- TOC entry 1859 (class 2606 OID 16475)
-- Dependencies: 146 146
-- Name: perfil_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY perfil
    ADD CONSTRAINT perfil_pkey PRIMARY KEY (nome);


--
-- TOC entry 1865 (class 2606 OID 16477)
-- Dependencies: 150 150
-- Name: profissional_convenio_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY profissional_convenio
    ADD CONSTRAINT profissional_convenio_pkey PRIMARY KEY (id);


--
-- TOC entry 1863 (class 2606 OID 16479)
-- Dependencies: 149 149
-- Name: profissional_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY profissional
    ADD CONSTRAINT profissional_pkey PRIMARY KEY (cpf);


--
-- TOC entry 1867 (class 2606 OID 16481)
-- Dependencies: 152 152
-- Name: receita_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY receita
    ADD CONSTRAINT receita_pkey PRIMARY KEY (id);


--
-- TOC entry 1871 (class 2606 OID 16483)
-- Dependencies: 155 155 155
-- Name: usuario_perfil_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario_perfil
    ADD CONSTRAINT usuario_perfil_pkey PRIMARY KEY (usuario, perfil);


--
-- TOC entry 1869 (class 2606 OID 16485)
-- Dependencies: 154 154
-- Name: usuario_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT usuario_pkey PRIMARY KEY (login);


--
-- TOC entry 1872 (class 2606 OID 16486)
-- Dependencies: 1846 142 140
-- Name: consulta_convenio_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_convenio_fkey FOREIGN KEY (convenio) REFERENCES convenio(cnpj);


--
-- TOC entry 1873 (class 2606 OID 16491)
-- Dependencies: 140 1854 144
-- Name: consulta_paciente_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_paciente_fkey FOREIGN KEY (paciente) REFERENCES paciente(id);


--
-- TOC entry 1874 (class 2606 OID 16496)
-- Dependencies: 149 1862 140
-- Name: consulta_profissional_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_profissional_fkey FOREIGN KEY (profissional) REFERENCES profissional(cpf);


--
-- TOC entry 1875 (class 2606 OID 16501)
-- Dependencies: 143 1850 147
-- Name: perfil_funcionalidade_funcionalidade_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY perfil_funcionalidade
    ADD CONSTRAINT perfil_funcionalidade_funcionalidade_fkey FOREIGN KEY (funcionalidade) REFERENCES funcionalidade(id);


--
-- TOC entry 1876 (class 2606 OID 16506)
-- Dependencies: 146 1858 147
-- Name: perfil_funcionalidade_perfil_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY perfil_funcionalidade
    ADD CONSTRAINT perfil_funcionalidade_perfil_fkey FOREIGN KEY (perfil) REFERENCES perfil(nome);


--
-- TOC entry 1878 (class 2606 OID 16511)
-- Dependencies: 142 1848 150
-- Name: profissional_convenio_convenio_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY profissional_convenio
    ADD CONSTRAINT profissional_convenio_convenio_fkey FOREIGN KEY (convenio) REFERENCES convenio(nome);


--
-- TOC entry 1879 (class 2606 OID 16516)
-- Dependencies: 150 1862 149
-- Name: profissional_convenio_profissional_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY profissional_convenio
    ADD CONSTRAINT profissional_convenio_profissional_fkey FOREIGN KEY (profissional) REFERENCES profissional(cpf);


--
-- TOC entry 1877 (class 2606 OID 16521)
-- Dependencies: 154 1868 149
-- Name: profissional_login_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY profissional
    ADD CONSTRAINT profissional_login_fkey FOREIGN KEY (login) REFERENCES usuario(login);


--
-- TOC entry 1880 (class 2606 OID 16526)
-- Dependencies: 1842 152 140
-- Name: receita_consulta_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY receita
    ADD CONSTRAINT receita_consulta_fkey FOREIGN KEY (consulta) REFERENCES consulta(id);


--
-- TOC entry 1881 (class 2606 OID 16531)
-- Dependencies: 149 1862 152
-- Name: receita_registro_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY receita
    ADD CONSTRAINT receita_registro_fkey FOREIGN KEY (registro) REFERENCES profissional(cpf);


--
-- TOC entry 1882 (class 2606 OID 16536)
-- Dependencies: 155 146 1858
-- Name: usuario_perfil_perfil_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY usuario_perfil
    ADD CONSTRAINT usuario_perfil_perfil_fkey FOREIGN KEY (perfil) REFERENCES perfil(nome);


--
-- TOC entry 1883 (class 2606 OID 16541)
-- Dependencies: 155 154 1868
-- Name: usuario_perfil_usuario_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY usuario_perfil
    ADD CONSTRAINT usuario_perfil_usuario_fkey FOREIGN KEY (usuario) REFERENCES usuario(login);


--
-- TOC entry 1888 (class 0 OID 0)
-- Dependencies: 6
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2012-12-07 00:45:18

--
-- PostgreSQL database dump complete
--

